package models

import (
	"github.com/cy77cc/hioshop/global"
)

type Keywords struct {
	Model
	Keyword   string `json:"keyword" gorm:"type:varchar(90);default:''"`
	IsHot     uint8  `json:"is_hot" gorm:"type:tinyint unsigned;default:0"`
	IsDefault uint8  `json:"is_default" gorm:"type:tinyint unsigned;default:0"`
	IsShow    uint8  `json:"is_show" gorm:"type:tinyint unsigned;default:1"`
	SortOrder uint   `json:"sort_order" gorm:"type:int unsigned;default:100"`
	SchemeUrl string `json:"scheme_url" gorm:"type:varchar(255);default:''"`
	Type      uint   `json:"type" gorm:"type:int unsigned;default:0"`
}

func (Keywords) GetDefaultKeywords() (Keywords, error) {
	defaultKeywords := Keywords{}
	err := global.DB.Model(&Keywords{}).Where("is_default=1").Limit(1).Find(&defaultKeywords).Error
	return defaultKeywords, err
}

func (Keywords) GetHotKeywordList() ([]string, error) {
	list := make([]string, 10)

	err := global.DB.Model(&Keywords{}).Select("keyword").Distinct("keyword").Limit(10).Select(&list).Error
	return list, err
}
